<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
    <style>
        .layui-card {border:1px solid #f2f2f2;border-radius:5px;}
        .icon {margin-right:10px;color:#1aa094;}
        .icon-cray {color:#ffb800!important;}
        .icon-blue {color:#1e9fff!important;}
        .icon-tip {color:#ff5722!important;}
        .layuimini-qiuck-module {text-align:center;margin-top: 10px}
        .layuimini-qiuck-module a i {display:inline-block;width:100%;height:60px;line-height:60px;text-align:center;border-radius:2px;font-size:30px;background-color:#F8F8F8;color:#333;transition:all .3s;-webkit-transition:all .3s;}
        .layuimini-qiuck-module a cite {position:relative;top:2px;display:block;color:#666;text-overflow:ellipsis;overflow:hidden;white-space:nowrap;font-size:14px;}
        .welcome-module {width:100%;height:210px;}
        .panel {background-color:#fff;border:1px solid transparent;border-radius:3px;-webkit-box-shadow:0 1px 1px rgba(0,0,0,.05);box-shadow:0 1px 1px rgba(0,0,0,.05)}
        .panel-body {padding:10px}
        .panel-title {margin-top:0;margin-bottom:0;font-size:12px;color:inherit}
        .label {display:inline;padding:.2em .6em .3em;font-size:75%;font-weight:700;line-height:1;color:#fff;text-align:center;white-space:nowrap;vertical-align:baseline;border-radius:.25em;margin-top: .3em;}
        .layui-red {color:red}
        .main_btn > p {height:40px;}
        .layui-bg-number {background-color:#F8F8F8;}
        .layuimini-notice:hover {background:#f6f6f6;}
        .layuimini-notice {padding:7px 16px;clear:both;font-size:12px !important;cursor:pointer;position:relative;transition:background 0.2s ease-in-out;}
        .layuimini-notice-title,.layuimini-notice-label {
            padding-right: 70px !important;text-overflow:ellipsis!important;overflow:hidden!important;white-space:nowrap!important;}
        .layuimini-notice-title {line-height:28px;font-size:14px;}
        .layuimini-notice-extra {position:absolute;top:50%;margin-top:-8px;right:16px;display:inline-block;height:16px;color:#999;}
    </style>
</head>

<body>
    <div class="layui-container">
        <div class="layui-row">
            <div class="layui-col-lg-offset3" layui-col-lg6>
                <div class="layui-form layuimini-form">
                    <form class="layui-form" action="" lay-filter="userForm">
                        <div class="layui-form-item">
                            <label class="layui-form-label"><i class="fa fa-bookmark-o"></i> 名字：</label>
                            <div class="layui-input-block">
                                <input type="text" name="name" required lay-verify="required" placeholder="请输入名字"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <input type="hidden" name="id" value="" class="layui-input">
    
                        <div class="layui-form-item">
                            <label class="layui-form-label"><i class="fa fa-users"></i> 按摩Id：</label>
                            <div class="layui-input-inline">
                                <select id="massageId" name="massageId" lay-verify="required"  class="select">
                                       <option value="" >请选择服务</option>
                                </select>
                            </div>
                        </div>
    
    
                        <div class="layui-form-item">
                            <label class="layui-form-label"><i class="fa fa-tint"></i> 洗浴Id：</label>
                            <div class="layui-input-inline">
                                <select id="washId" name="washId" lay-verify="required"  class="select">
                                       <option value="" >请选择服务</option>
                                </select>
                            </div>
    
                        </div>
                        <input type="hidden" name="expend" value="" class="layui-input">
                        <!--<div class="layui-form-item">
                            <label class="layui-form-label"><i class="fa fa-jpy"></i> 花费：</label>
                            <div class="layui-input-block">
                                <input type="text" name="expend" required lay-verify="required" placeholder="请输入人数"
                                       autocomplete="off" class="layui-input">
                            </div>
    
                        </div>-->
    
    
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit lay-filter="formDemo"><i class="fa fa-check-square-o"></i> 提交</button>
                                <button type="reset" class="layui-btn layui-btn-primary"><i class="fa fa-repeat"></i> 重置</button>
                            </div>
                        </div>
                    </form>
                </div>
    
            </div>
        </div>
    </div>



<script>
    //Demo
    layui.use(['form','upload','element'], function () {
        // 表单对象  form
        var form = layui.form
            //jquery 对象 $
            , $ = layui.jquery
            ,element = layui.element
            ,upload = layui.upload
            // 日期组件
            , laydate = layui.laydate;

        //日期   渲染上面 id 为 date 的 标签
        laydate.render({
            elem: '#date'
        });

        // 从 localStorage 把数据取出来   并转成 js 对象
        //  JSON.parse("str")   把字符串转为 js 对象
        var data = JSON.parse(localStorage.getItem("border"));
       
        $.ajax({
	        url: 'http://localhost:8080/border/selectBmassage',
	        dataType: 'json',
	        type: 'post',
	        success: function(result) {
	            if (result.data!== null) {
	            	$("#massageId").empty();
                	$("#massageId").append(new Option("请选择服务", "0"));
	                $.each(result.data.massageId, function(index,item) {                   
	                    $('#massageId').append(new Option(item.name,item.id));
	                });
	            } else {
	                $("#massageId").append(new Option("暂无数据", ""));
	            }
	            //重新渲染
	            form.render("select");
	        }
	    });

        $.ajax({
	        url: 'http://localhost:8080/border/selectBwash',
	        dataType: 'json',
	        type: 'post',
	        success: function(result) {
	            if (result.data!== null) {
	            	$("#washId").empty();
                	$("#washId").append(new Option("请选择服务", "0"));
	                $.each(result.data.washId, function(index,item) {                   
	                    $('#washId').append(new Option(item.name,item.id));
	                });
	            } else {
	                $("#washId").append(new Option("暂无数据", ""));
	            }
	            //重新渲染
	            form.render("select");
	        }
	    });

        //给表单数据赋值
        form.val("userForm",{
            "name":data.name,
            "massageId":data.massageId,
            "id":data.id,
            "washId":data.washId,
            "expend":data.expend
            
        });
       
        $("#massageId").val(data.massageId);
        $("#washId").val(data.washId);
        form.render("select");
  


        // token 前后端分离再用
       // var token = JSON.parse(localStorage.getItem("token"));


        //监听提交
        form.on('submit(formDemo)', function (data) {
            //layer.msg(JSON.stringify(data.field));
            $.ajax({
                "url":"http://localhost:8080/border/updateBorder",
               // "headers":{"token":token},
                "data": data.field,
                // result 参数 表式后台响应的数据
                "success":function(result){
                    var str =  JSON.stringify(result);
                    //console.log("----------------"+str);
                    if(result.code == 200){

                        // 关闭 弹出层
                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(iframeIndex);

                    }else{
                        layer.msg(result.msg);
                    }
                },
                "dataType":"json"
            });

            return false;
        });
    });
</script>


</body>

</html>